var gSuppliers = {};
var gSupplierSelect;
var gMagazineSelect;
var gMagazineMap = {};
function initSuppliers(){
	gSupplierSelect = document.getElementById("subscription_edit_form:subscriptionSupplier");
	gMagazineSelect = document.getElementById("subscription_edit_form:subscriptionMagazine");
	var suppliers = gSupplierSelect.getElementsByTagName('option');
	for(var i = 0; i < suppliers.length; ++i){
		var currentSupplier = suppliers[i];
		gSuppliers[currentSupplier.value] = currentSupplier.text;
	}
	displayMagazineSuppliers();
}

function displayMagazineSuppliers(){
	var lMagazineValue = gMagazineSelect.value;
	gSupplierSelect.innerHTML = "";
	var lAvailableSuppliers = gMagazineMap[parseInt(lMagazineValue)];
	if(lAvailableSuppliers && lAvailableSuppliers.length > 0){
		for(var i = 0; i < lAvailableSuppliers.length; ++i){
			var lSupplierId = lAvailableSuppliers[i];
			var lOption = document.createElement("option");
			lOption.value = lSupplierId;
			lOption.text = gSuppliers[lSupplierId];
			gSupplierSelect.appendChild(lOption);
		}
	}else{
		var lOption = document.createElement("option");
		lOption.value = null;
		lOption.text = "No suppliers for this magazine";
		gSupplierSelect.appendChild(lOption);
	}
}
